import { _decorator, Label, Button } from 'cc';
const { ccclass, property } = _decorator;

import DialogBase from "../../lib/dialog/DialogBase";
// import { DialogMgr } from "../lib/dialog/DialogMgr";
/**
 * 对话框警告 界面
 * @description 交流群：415468592
 */
@ccclass('AlertView')
export default class AlertView extends DialogBase {
    @property({ type: Label, displayName: '要说的内容' })
    public lbl_content: Label | null = null;
    @property({ type: Button, displayName: '确认按钮' })
    public btn_sure: Button | null = null;
    @property({ type: Button, displayName: '关闭按钮' })
    public btn_close: Button | null = null;
    private sure_fun: Function = null;
    private close_fun: Function = null;
    onLoad() {
        this.btn_sure.node.on("click", this.onClickSure, this);
        this.btn_close.node.on("click", this.onClickClose, this);
    }
    onEnable() {
        this.initView();
    }

    private initView() {
        this.initContent();
    }
    private initContent() {
        // 文本内容
        if (typeof this.dialog_data == "string") {
            this.lbl_content.string = this.dialog_data;
        } else if (typeof this.dialog_data == "object" && typeof this.dialog_data.content == "string") {
            this.lbl_content.string = this.dialog_data.content;
        }
        // 文本尺寸
        if (this.dialog_data && typeof this.dialog_data.size == "number") {
            this.lbl_content.fontSize = this.dialog_data.size;
        }
    }
    /**
    * 初始化回调函数
    * @param sure_fun
    * @param close_fun
    */
    public initCall(sure_fun?: Function, close_fun?: Function) {
        this.sure_fun = sure_fun;
        this.close_fun = close_fun;
        this.btn_sure.node.active = !!sure_fun;
        this.btn_close.node.active = !!close_fun;
    }
    private onClickClose() {
        typeof this.close_fun == "function" && this.close_fun();
        this.closeDialog();
    }
    private onClickSure() {
        typeof this.sure_fun == "function" && this.sure_fun();
        this.closeDialog();
    }
    onDestroy() {
        super.onDestroy();
        this.sure_fun = null;
        this.close_fun = null;
    }
    // update (dt) {}
}

